/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 */

import { LogServiceImpl } from '../../../../../src/base/internal/pool/log-collection/log-service-impl';
import { ScheduleLog, WorkLog } from '../../../../../src/base/internal/pool/log-collection/log';
import { LogType } from '../../../../../src/base/internal/pool/enum/log-type';

describe('test log service impl', () => {
  const logService = new LogServiceImpl();
  test('test addLog', () => {
    logService.end();
    const workLog: WorkLog = {
      type: LogType.WORK,
      time: '',
      workerId: 0,
      content: '',
      taskPath: '',
      taskName: '',
      taskCompletePath: ''
    };
    logService.addLog(workLog);
    expect(logService.getLog(LogType.WORK)!.size === 0).toBeTruthy();
    const scheduleLog: ScheduleLog = {
      type: LogType.SCHEDULE,
      time: '',
      workerId: 0,
      workId: ''
    };
    logService.addLog(scheduleLog);
    expect(logService.getLog(LogType.SCHEDULE)!.size === 0).toBeTruthy();
    logService.start();
    logService.addLog(workLog);
    expect(logService.getLog(LogType.WORK)!.size === 1).toBeTruthy();
    logService.addLog(scheduleLog);
    expect(logService.getLog(LogType.SCHEDULE)!.size === 1).toBeTruthy();
  });

  test('test getLog', () => {
    expect(logService.getLog(LogType.WORK)!.size === 1).toBeTruthy();
    expect(logService.getLog(LogType.SCHEDULE)!.size === 1).toBeTruthy();
    const a: any = 1;
    expect(logService.getLog(a)).toBeUndefined();
  });

  test('test clear', () => {
    logService.clear();
    expect(logService.getLog(LogType.WORK)).toBeUndefined();
    expect(logService.getLog(LogType.SCHEDULE)).toBeUndefined();
  });
});
